﻿//  Copyright (c) 2011 Ray Liang (http://www.dotnetage.com)
//  Licensed MIT: http://www.opensource.org/licenses/mit-license.php

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DNA.Mvc.Exporting
{
    public abstract class Exporter : Command<ExportingContext>
    {
        private string resBaseName = "language";

        /// <summary>
        /// Gets the exporter name.
        /// </summary>
        public virtual string Name { get; set; }

        public virtual bool Visible { get { return true; } }

        public virtual int Order { get; set; }

        /// <summary>
        /// Gets/Sets the match key that gets the parameter in context data.
        /// </summary>
        public virtual string MatchKey { get; set; }

        protected T GetMatch<T>(ExportingContext context)
        {
            if (string.IsNullOrEmpty(MatchKey)) throw new ArgumentNullException("MatchKey");

            if (context.Data[MatchKey] == null)
            {
                context.Trace.Warn(string.Format("{0} exporter execution error:The param object {1} is not found in execution context.", Name, MatchKey));
                return default(T);
            }
            return (T)context.Data[MatchKey];
        }

        /// <summary>
        /// Gets description for this exporter.
        /// </summary>
        public virtual string Description { get; set; }

        public virtual string ResBaseName
        {
            get { return resBaseName; }
            set { resBaseName = value; }
        }

        public virtual string ResKey { get; set; }

    }
}
